using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Collections.Specialized;
using System.Configuration.Provider;
using System.IO;

namespace Commerce.Providers
{
    public class CCPaymentProvider:PaymentProvider
    {

        //properties
        #region Passed-in Props
        string currencyCode = "USD";
        #endregion

        #region Provider specific behaviors

        public override void Initialize(string name, NameValueCollection config)
        {

            // Verify that config isn't null
            if (config == null)
                throw new ArgumentNullException("config");
           
            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                config.Remove("name");
                config.Add("name",
                    "CCPaymentProvider");
            }            
            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description",
                    "CC Payment Provider");
            }
            base.Initialize(name, config);

            currencyCode = config["currencyCode"].ToString();
            if (String.IsNullOrEmpty(currencyCode))
                throw new ProviderException("Empty Currency Code value");
            config.Remove("currencyCode");

        
        }

        public override string Name
        {
            get
            {
                return null;
            }
        }
        #endregion

        public override Commerce.Common.Transaction Charge(Commerce.Common.Order order)
        {
            //string sOut = "";

            decimal dTotal = order.OrderTotal;
            int roundTo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits;
            dTotal = Math.Round(dTotal, roundTo);

            //make sure that the ExpMonth has a leading 0
            string sExpMonth = order.CreditCardExpireMonth.ToString();
            if (order.CreditCardExpireMonth < 10)
                sExpMonth = "0" + sExpMonth;

            Commerce.Common.Transaction trans = new Commerce.Common.Transaction();

            // save the payment info in the database - make sure it's encrypted



            trans.TransactionID = 99;

            return trans;
        }

        public override string Refund(Commerce.Common.Order order)
        {
            throw new Exception("This method not enabled for CCPayment");
        }

    }
}
